//
//  firstViewController.m
//  UIPageViewController
//
//  Created by apple on 15/9/24.
//  Copyright © 2015年 戴维营. All rights reserved.
//

#import "firstViewController.h"
#import "MMDrawerController.h"

@interface firstViewController ()

{
    UIScrollView *_scrollView;

}
@end

@implementation firstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.view.backgroundColor = [UIColor orangeColor];
    
    _scrollView = [self scrollView:self.view];
    
    [_scrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:NULL];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
{
    NSValue *value = change[NSKeyValueChangeNewKey];
    
    CGPoint point = value.CGPointValue;
    
    if (_currentPage == 0 && point.x <= self.view.frame.size.width)
    {
        _scrollView.panGestureRecognizer.enabled = NO;
        _scrollView.panGestureRecognizer.enabled = YES;
    }
    else
    {
        MMDrawerController *drwerCtrl = (MMDrawerController *)[UIApplication sharedApplication].keyWindow.rootViewController;
        
        
    }
    
}

//查找scrollView

- (UIScrollView *)scrollView:(UIView *)view
{
    for (UIView *v in view.subviews)
    {
        if ([v isKindOfClass:[UIScrollView class]])
        {
            return (UIScrollView *)v;
        }
   
        else
        {
            UIView *sv = [self scrollView:v];
            if (sv)
            {
                return (UIScrollView *)sv;
            }
        }
    }
        return nil;
}

- (void)dealloc
{
    [_scrollView removeObserver:self forKeyPath:@"contentOffset"];
}

@end
